//
// Pomme.cpp for nibbler in /home/titouan/Dropbox/Code/nibbler-epitech-2017/inc
//
// Made by Titouan Creach
// Login   <titouan@epitech.net>
//
// Started on  Mon Mar 24 12:53:54 2014 Titouan Creach
// Last update Mon Mar 24 13:41:02 2014 Titouan Creach
//

#include <cstdlib>
#include "Pomme.hpp"


Pomme::Pomme(int w, int h)
  : _w(w)
  , _h(h)
{
}

Point Pomme::getPosition() const
{
  return (_pos);
}

Point Pomme::newPomme(const std::deque<Point> &snakePos)
{
  Point ret;
  Point dispo;

  dispo.x = (_w / 16) - 2;
  dispo.y = (_h / 16) - 2;

  do
    {

      ret.x = rand() % dispo.x;
      ret.y = rand() % dispo.y;

      ++ret.x;
      ++ret.y;


    } while (collision(snakePos, ret));



  _pos = ret;

  return (ret);
}

bool Pomme::collision(const std::deque<Point> &snakePos, Point p)
{
  std::deque<Point>::const_iterator it;

  for (it = snakePos.begin() ; it != snakePos.end() ; ++it)
    {
      if (it->x == (p.x) && it->y == (p.y))
	return (true);
    }
  return (false);
}
